package com.tourismhengyang.actions;

import java.util.List;

import javax.servlet.http.HttpSession;

import org.apache.struts2.ServletActionContext;

import com.opensymphony.xwork2.ActionSupport;
import com.tourismhengyang.beans.Forum;
import com.tourismhengyang.beans.LocalInfo;
import com.tourismhengyang.biz.IForumBiz;
import com.tourismhengyang.biz.ILocalInfoBiz;
import com.tourismhengyang.impl.ForumBizImpl;
import com.tourismhengyang.impl.LocalInfoBizImpl;
import com.tourismhengyang.utils.JsonObject;

public class ForumAction extends ActionSupport {
	private static final long serialVersionUID = 1L;
	private IForumBiz forumBiz = new ForumBizImpl();
	private ILocalInfoBiz localInfoBiz = new LocalInfoBizImpl();
	private Forum forum;
	private HttpSession session;
	private JsonObject json;
	
	public String addComment() {
		int result = forumBiz.addComment(forum);
		json = new JsonObject();
		if(result > 0) {
			json.setResult(result);
		} else {
			json.setResult(0);
		}
		return SUCCESS;
	}
	
	public String goForum() {
		session = ServletActionContext.getRequest().getSession();
		LocalInfo li = localInfoBiz.getInfoByLid(forum.getLid());
		json = new JsonObject();
		if(li != null) {
			session.setAttribute("localInfo_forum", li);
			json.setObj(li);
		}
		return SUCCESS;
	}
	
	public String getComments(){
		List<Forum> list = forumBiz.getComments(forum.getLid());
		json = new JsonObject();
		if(list != null) {
			json.setRows(list);
			json.setTotal(list.size());
		} else {
			json.setRows(null);
			json.setTotal(0);
		}
		return SUCCESS;
	}
	
	public Forum getForum() {
		return forum;
	}
	
	public void setForum(Forum forum) {
		this.forum = forum;
	}
	
	public JsonObject getJson() {
		return json;
	}
	
	public void setJson(JsonObject json) {
		this.json = json;
	}
}
